package com.dingup.mock.bean.listening;

import com.google.gson.Gson;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yanggavin on 16/4/13.
 */
public class ListeningQuestionXml {
    private String title;
    private String type;
    private List<String> answer;
    private String tip;
    private String expl;
    private String titleAudioUrl;
    private String repeatAudioUrl;
    private HashMap<String, String> options;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public List<String> getAnswer() {
        return answer;
    }

    public void setAnswer(List<String> answer) {
        this.answer = answer;
    }

    public String getTip() {
        return tip;
    }

    public void setTip(String tip) {
        this.tip = tip;
    }

    public String getExpl() {
        return expl;
    }

    public void setExpl(String expl) {
        this.expl = expl;
    }

    public HashMap<String, String> getOptions() {
        return options;
    }

    public void setOptions(HashMap<String, String> options) {
        this.options = options;
    }

    public String getTitleAudioUrl() {
        return titleAudioUrl;
    }

    public void setTitleAudioUrl(String titleAudioUrl) {
        this.titleAudioUrl = titleAudioUrl;
    }

    public String getRepeatAudioUrl() {
        return repeatAudioUrl;
    }

    public void setRepeatAudioUrl(String repeatAudioUrl) {
        this.repeatAudioUrl = repeatAudioUrl;
    }

    public String toXmlString(){
        StringBuilder xmlBuilder = new StringBuilder();
        xmlBuilder.append("<root>");
        xmlBuilder.append(String.format("<title>%s</title>", title));
        xmlBuilder.append(String.format("<type>%s</type>", type));
        xmlBuilder.append(String.format("<answer>%s</answer>", org.apache.commons.lang.StringUtils.join(answer, ",")));
        xmlBuilder.append(String.format("<tip>%s</tip>", tip));
        xmlBuilder.append(String.format("<expl>%s</expl>", expl));
        xmlBuilder.append(String.format("<title_audio_url>%s</title_audio_url>", titleAudioUrl));
        xmlBuilder.append(String.format("<repeat_audio_url>%s</repeat_audio_url>", repeatAudioUrl));
        xmlBuilder.append("<options>");
        if (options != null) {
            for (Map.Entry<String, String> entry : options.entrySet()) {
                xmlBuilder.append(String.format("<%s>%s</%s>", entry.getKey(), entry.getValue(), entry.getKey()));
            }
        }
        xmlBuilder.append("</options>");
        xmlBuilder.append("</root>");
        return xmlBuilder.toString();
    }

    public String toJsonString(){
        Gson gson = new Gson();
        return gson.toJson(this);
    }
}
